package com.allwees.bs.c.configuration;

import com.allwees.bs.c.module.sys.entity.SysFileInfo;
import com.allwees.bs.c.module.sys.repository.SysFileInfoRepository;
import com.allwees.core.common.util.reflect.PojoUtil;
import com.allwees.support.fileservice.config.FileConfig;
import com.allwees.support.fileservice.upload.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class UploadConfiguration {

    @Autowired
    private FileConfig config;

    @Bean
    public UploadFileUtil uploadFileUtil(SysFileInfoRepository sysFileInfoRepository) {
        UploadFileUtil uploadFileUtil = new UploadFileUtil();
        uploadFileUtil.init(config, fileInfo -> sysFileInfoRepository.save(PojoUtil.copy(new SysFileInfo(), fileInfo)));
        return uploadFileUtil;
    }
}
